<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;
use const support\shortcut_type_1;
use const support\shortcut_type_remarks;

/**
 * @property integer $id ID(主键)
 * @property string $shortcut_title 快捷标题
 * @property string $shortcut_icon 快捷图片
 * @property integer $sort 排序，排序越大越在前
 * @property integer $shortcut_type 快捷类型，0无，1商品详情，2分类
 * @property string $shortcut_value 场景值
 * @property integer $status 状态，1正常，2关闭
 * @property integer $create_time 创建时间
 * @property integer $update_time 更新时间
 */
class RlShortcut extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'rl_shortcuts';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    protected $appends=[
        'shortcut_type_text','shortcut_value_text','create_date'
    ];

    public function getShortcutTypeTextAttribute(): string
    {
        return shortcut_type_remarks[$this->shortcut_type]??'未知';
    }

    public function getShortcutValueTextAttribute()
    {
        if ($this->shortcut_type==shortcut_type_1){
            return RlGoods::where('id',$this->shortcut_value)->value('goods_title');
        }else{
            return RlGoodsCate::where('id',$this->shortcut_value)->value('cate_title');
        }
    }

    public function getCreateDateAttribute()
    {
        return $this->update_time?date('Y-m-d H:i:s',$this->update_time):'';
    }
    
}
